package org.dydl.dao.system.repository;

import org.dydl.model.system.MaterialsPurchase;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface IMaterialsPurchaseRepository extends CrudRepository<MaterialsPurchase, Integer>,JpaSpecificationExecutor<MaterialsPurchase>{
	
	
	@Query(value = " FROM MaterialsPurchase ", countQuery = "SELECT count(id) FROM MaterialsPurchase")
	Page<MaterialsPurchase> getList(Pageable pageable);
	
	@Query(value = " FROM MaterialsPurchase WHERE purchaseSingleNo LIKE :purchaseSingleNo ", countQuery = "SELECT count(id) FROM MaterialsPurchase WHERE purchaseSingleNo LIKE :purchaseSingleNo ")
	Page<MaterialsPurchase> getListLike(@Param("purchaseSingleNo") String purchaseSingleNo, Pageable pageable);
	
	@Query(value = "SELECT * FROM materials_purchase WHERE PURCHASE_SINGLE_NO = :purchaseSingleNo",nativeQuery = true)
	MaterialsPurchase findByPurchaseSingleNo(@Param("purchaseSingleNo")String purchaseSingleNo);

	@Modifying
	@Query(value = "UPDATE materials_purchase SET STATUS = :status WHERE ID = :id",nativeQuery = true)
	void changeExamine(@Param("id")Integer id, @Param("status")Integer status );

	@Modifying
	@Query(value = "update materials_purchase  set STATUS =:status  where PURCHASE_SINGLE_NO = :purchaseSingleNo", nativeQuery = true)
	int updateMaterialsPurchaseStatus(@Param("status")Integer status,@Param("purchaseSingleNo")String purchaseSingleNo);
}
